﻿using System;
using System.Collections.Generic;
using System.Linq;
using CodeContrib.Resources;

namespace CodeContrib
{
	public static class Guard
	{
		public static void NotNegative(decimal value, string parameterName)
		{
			if (value < 0)
			{
				throw new ArgumentOutOfRangeException(parameterName, Strings.CannotBeNegative_Format.FormatWith(parameterName));
			}
		}

		public static void NotNegative(float value, string parameterName)
		{
			if (value < 0)
			{
				throw new ArgumentOutOfRangeException(parameterName, Strings.CannotBeNegative_Format.FormatWith(parameterName));
			}
		}

		public static void NotNegative(int value, string parameterName)
		{
			if (value < 0)
			{
				throw new ArgumentOutOfRangeException(parameterName, Strings.CannotBeNegative_Format.FormatWith(parameterName));
			}
		}

		public static void NotNegativeOrZero(decimal value, string parameterName)
		{
			if (value <= 0)
			{
				throw new ArgumentOutOfRangeException(parameterName, Strings.CannotBeNegativeOrZero_Format.FormatWith(parameterName));
			}
		}

		public static void NotNegativeOrZero(float value, string parameterName)
		{
			if (value <= 0)
			{
				throw new ArgumentOutOfRangeException(parameterName, Strings.CannotBeNegativeOrZero_Format.FormatWith(parameterName));
			}
		}

		public static void NotNegativeOrZero(int value, string parameterName)
		{
			if (value <= 0)
			{
				throw new ArgumentOutOfRangeException(parameterName, Strings.CannotBeNegativeOrZero_Format.FormatWith(parameterName));
			}
		}

		public static void NotNull(object value, string parameterName)
		{
			if (value == null)
			{
				throw new ArgumentNullException(parameterName, Strings.CannotBeNull_Format.FormatWith(parameterName));
			}
		}

		public static void NotNullOrEmpty(string value, string parameterName)
		{
			if (string.IsNullOrEmpty(value))
			{
				throw new ArgumentException(Strings.CannotBeNullOrEmpty_Format.FormatWith(parameterName), parameterName);
			}
		}

		public static void NotNullOrEmpty<T>(IEnumerable<T> collection, string parameterName)
		{
			if (collection == null
			    || !collection.Any())
			{
				throw new ArgumentException(Strings.CollectionCannotBeEmpty_Format.FormatWith(parameterName), parameterName);
			}
		}

		public static void NotNullOrWhitespace(string value, string parameterName)
		{
			if (string.IsNullOrWhiteSpace(value))
			{
				throw new ArgumentException(Strings.CannotBeNullOrWhitespace_Format.FormatWith(parameterName), parameterName);
			}
		}
	}
}